#include<cstdio>
#include<cstring>
const int maxn=1010;
int n,m;
int c[maxn][maxn],a[maxn][maxn];
int low(int x)
{
	return x&(x^(x-1));
}
void add(int x,int y,int val)
{
	for(int i=x;i>0;i-=low(i))
		for(int j=y;j>0;j-=low(j))
			c[i][j]+=val;
}
int sum(int x,int y)
{
	int ans=0;
	for(int i=x;i<=n;i+=low(i))
		for(int j=y;j<=n;j+=low(j))
			ans+=c[i][j];
	return ans;
}
int main()
{
	freopen("test.in","r",stdin);
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		memset(c,0,sizeof(c));
		for(int i=1;i<=m;i++)
		{
			char ch;
			int x,y,xx,yy;
			scanf("%c%c",&ch,&ch);
			if(ch=='C')
			{
				scanf("%d%d%d%d",&x,&y,&xx,&yy);
				add(xx,yy,1);
				add(x-1,y-1,1);
				add(xx,y-1,-1);
				add(x-1,yy,-1);
			}
			if(ch=='Q')
			{
				scanf("%d%d",&x,&y);				
				printf("%d\n",sum(x,y)%2);
			}
		}
		printf("\n");
	}
	return 0;
}
